import Ember from 'ember';

export default Ember.Controller.extend({
  valueIsNull: false,
  actions:{
    invalid() {
      this.set('valueIsNull',false);
    },
    //弹窗取消
    invitation() {
        this.set('showEditModal', false);
        this.set('confModel', null);
        this.set('valueIsNull',false);
    },
    //保存按钮
    saveClick: function() {
        var _self = this;
        var inputValue = this.get("inputValue");
        var confModel = this.get("confModel");
        if(!inputValue){
          this.set('valueIsNull',true);
          return;
        } else {
          this.set('valueIsNull',false);
          confModel.set("value", inputValue);
          _self.set("showEditModal", false);
        }
        var mainpageController = App.lookup('controller:business.mainpage');
        App.lookup('controller:business.mainpage').openPopTip("正在保存");
        confModel.save().then(function() {
            App.lookup('controller:business.mainpage').showPopTip("保存成功");
        },function(err){
          let error = err.errors[0];
          if(error.code==="4"){
            confModel.validate().then(function(){
              confModel.addError('value',['参数设置出错']);
              confModel.set("validFlag",Math.random());
              App.lookup('controller:business.mainpage').showPopTip("保存失败",false);
            });
          }
        });
    },
    //编辑按钮
    editClick(conf){
      this.set('showEditModal', true);
      if (!conf) {
          return null;
      }
      this.set('confModel', conf);
      this.set('inputValue', conf.get("value"));
    },
  }
});
